/**
 * Created by Administrator on 2017/8/23.
 */

function setcookie(key,value,date,path,domain,secure){
    var str = "";
    if(key&&value){
        str += encodeURIComponent(key)+"="+encodeURIComponent(value)+";";
    }
    if(date instanceof Date){
        str += "expires="+date+";";
    }
    if(path){
        str += "path="+path+";";
    }
    if(domain){
        str += "domain="+domain+";";
    }
    if(secure=="secure"){
        str += "secure";
    }
    document.cookie = str;
}

//获取cookie的操作
function getCookieAll(){
    var obj = {};
    var str = document.cookie;
    if(str.indexOf(";")!=-1){
        //表示有多条内容
        var arr1 = str.split(";");
        for(var i=0;i<arr1.length;i++){
            var arr2 = arr1[i].split("=");
            obj[decodeURIComponent(arr2[0].trim())]=decodeURIComponent(arr2[1].trim());//trim()表示去掉空格
        }
    }else{
        if(str.indexOf("=")!=-1){
            var arr = str.split("=");
            obj[decodeURIComponent(arr[0])] = decodeURIComponent(arr[1]);
        }

    }
    return obj;
}



//根据键获取值
function getCookieValueByKey(key){
    var obj = getCookieAll();
    return obj[key];
}
// console.log(getCookieValueByKey("uname3"));

//删除
function remove(key){
    var date = new Date();
    date.setDate(date.getDate()-10000);
    document.cookie = encodeURIComponent(key)+"=;expires="+date;
}